package com.littlebee.storysuper.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.littlebee.storysuper.R;
import com.littlebee.storysuper.entry.EnglishEntry;
import com.littlebee.storysuper.entry.EnglistListEntry;
import com.littlebee.storysuper.entry.StorySeriesEntry;
import com.littlebee.storysuper.widget.RoundAngleImageView;

import java.util.List;

public class CircleGridEnglistAdapter extends BaseAdapter {

    private List<EnglistListEntry> mFiles;
    private LayoutInflater mLayoutInflater;
    private Context mContext;

    public CircleGridEnglistAdapter(List<EnglistListEntry> files, Context context) {
        this.mFiles = files;
        mLayoutInflater = LayoutInflater.from(context);
        this.mContext = context;
    }

    @Override
    public int getCount() {
        if(mFiles==null){
            return 0;
        }
        return mFiles.size();
    }

    @Override
    public EnglistListEntry getItem(int position) {

        return mFiles.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = mLayoutInflater.inflate(R.layout.item_gridview_circle_english, parent, false);
            holder.imageView = (RoundAngleImageView) convertView.findViewById(R.id.album_image);
            holder.title=(TextView)convertView.findViewById(R.id.tv_title);
            holder.title1=(TextView)convertView.findViewById(R.id.tv_title1);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final  EnglistListEntry entry=mFiles.get(position);
        // 根据屏幕宽度动态设置图片宽高
        holder.title.setText(entry.getCatoonseriesname());
        holder.title1.setText(entry.getCartoonseriesstagecount()+"集  热度："+entry.getCartoonserieshotpoint());
        Glide.with(mContext).load(entry.getCartoonseriesminiphotourl()).
                error(R.drawable.corner_photo_default_img).into(holder.imageView);

        return convertView;
    }

    private static class ViewHolder {
        RoundAngleImageView imageView;
        TextView title;
        TextView title1;
    }
}
